﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace Data_Access_Layer
{
    class getMaxId
    {
        private SqlConnection con;

        public getMaxId()
        {
            con = Connection.GetInstance().GetConnection();
        }

        public int maxId(string query)
        {
            SqlDataReader reader = null;
            int id = -1;

            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(query, con);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    id = reader.GetInt32(1);
                }
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return id;
        }

    }
}
